//
//  ViewController.m
//  18-SQLite
//
//  Created by GivenBmli on 16/8/8.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManger.h"
#import "Student.h"
@interface ViewController ()
@property (nonatomic , strong)SQLiteDataBaseManger *dataBaseManger;
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _dataBaseManger = [SQLiteDataBaseManger shareManger];
//    SQLite3
//    注意:使用SQLite需要引入libsqlite3.0.tbd
//    libsqlite3.0.tbd 和libsqlite3.tbd 区别
//    libsqlite3.0是libsqlite3的替身文件,防止用户误删
}
/**打开数据库*/
- (IBAction)openSQLite:(id)sender {
    [_dataBaseManger openSQLite3];
}
/**关闭数据库*/
- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManger closeSQLite3];
    
    
}
- (IBAction)createTable:(id)sender {
    [_dataBaseManger createTable];
    
    
}
- (IBAction)insertStu:(id)sender {

    Student *stu  =[[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"宝哥";
    [_dataBaseManger insertStu:stu];
    
}
- (IBAction)deleteStu:(id)sender {
//    Student *stu =[[Student alloc]init];
//    stu.stu_id = 38;
//    stu.stu_name = @"宝哥";
//    [_dataBaseManger insertStu:stu];
    [_dataBaseManger deleteAll];
}
- (IBAction)updateName:(id)sender {
    [_dataBaseManger updateOldName:@"宝哥" newName:@"王道林"];
}
- (IBAction)selectAll:(id)sender {
 NSArray *array = [_dataBaseManger selectAll];
    NSLog(@"%ld",array.count);
    NSLog(@"%@", array);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
